/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include "highfive/H5File.hpp"

#include "DBManager/IRepository/Input/Design/IDOPTPRMRepository.h"
#include "DBManager/Repository/HDF5/Base/SingleRepositoryBase.h"

template <>
inline HighFive::DataType HighFive::create_datatype<SG::DataStructure::FEM::DOPTPRMData> ()
{
    HighFive::CompoundType compoundType = { { "APRCOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "IPRINT", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DESMAX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "METHOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DELP", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DPMIN", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "PTOL", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "CONV1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "CONV2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "GMAX", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DELX", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DXMIN", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DELB", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "GSCAL", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "CONVDV", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "CONVPR", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "P1", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "CT", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "CTMIN", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DABOBJ", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DELOBJ", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DOBJ1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DOBJ2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DX1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DX2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "ISCAL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "ITMAX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "ITRMOP", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "IWRITE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "IGMAX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "JTMAX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "ITRMST", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "JPRINT", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "IPRNT1", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "IPRNT2", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "JWRITE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "STPSCL", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "FSDMAX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "FSDALP", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DISCOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DISBEG", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "PLVIOL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CR", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CDDV", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CP", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CC", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CM", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CBL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2RSET", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "P2CALL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "ADSCOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "PENAL", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DRATIO", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "AUTOSE", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "NUMDIV", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "TCHECK", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "TDMIN", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "TFWET", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "TREGION", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "EATA1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "EATA2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "EATA3", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "UPDFAC1", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "UPDFAC2", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DPMAX", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DXMAX", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "OPTCOD", HighFive::create_datatype<char[8]> (), 1, true },
                                            { "OBJMOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DELXESL", HighFive::create_datatype<SG::DataStructure::Common::Real> () },
                                            { "DSMXESL", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "NASPR0", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "LSCOD", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
                                            { "DOMAIN_ID", HighFive::create_datatype<SG::DataStructure::Common::Id> () } };
    return compoundType;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN

class DBManager_DECLSPEC DOPTPRMRepository : public IDOPTPRMRepository, public RepositoryBase
{
  public:
    explicit DOPTPRMRepository (HDF5Database& database);

    void InitialDatasetInfo ();

    /// @brief 写入配置
    /// @param entity
    virtual SG::DataStructure::Common::Status Set (const SG::DataStructure::FEM::DOPTPRMData& entity) override;

    /// @brief 获取配置
    /// @return
    virtual SG::DataStructure::FEM::DOPTPRMData Get () override;
};

SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
